package vcp.views;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Observable;
import java.util.Observer;

import javax.swing.event.AncestorListener;
import javax.swing.event.TableModelListener;

import client.Message;
import db.parking.beans.rates;
import vcp.common.AbstractView;
import vcp.common.IView;
import vcp.gui.panels.networkmanager.PnlRatesApproval;


/**
 * Rates Approval View
 *
 */
public class RatesApprovalView extends AbstractView implements IView,Observer{
    PnlRatesApproval pnlRatesApproval;
	public RatesApprovalView(){
		pnlRatesApproval = new PnlRatesApproval();
	}
	public PnlRatesApproval getPnlRatesApproval() {
		return pnlRatesApproval;
	}
	public void setPnlRatesApproval(PnlRatesApproval pnlRatesApproval) {
		this.pnlRatesApproval = pnlRatesApproval;
	}
	public void update(Observable o, Object arg) {

		Message recvmsg = (Message) arg;
		String func = recvmsg.getMsg();
		Object robj=recvmsg.getObj();
		//this.pnlRatesApproval.getRatesTable().getDtm()
		if (func.equals("GetModifiedRates") && robj!=null) {
			
			//this.pnlRatesApproval.getRatesTable().getDtm().getDataVector().isEmpty();
			@SuppressWarnings("unchecked")
			ArrayList<rates> list = 
					(ArrayList<rates>)robj;
			Iterator<rates> itty = list.iterator();
			Object obj[] = new Object[6];
			while (itty.hasNext()) {
				rates r = (rates) itty.next();
				obj[0] = r.getLotNo();
				obj[1] = r.getRateType();
				obj[2] = r.getRateName();
				obj[3] = r.getAmount();
				obj[4] = r.getTmpAmount();
				obj[5] = Boolean.parseBoolean((new Integer(r.getStatus())).toString());
				this.pnlRatesApproval.getRatesTable().getDtm().addRow(obj);
				//this.pnlRatesManagement.getRatesTable().getColumnModel().getColumn(0).setMaxWidth(0);
				//this.pnlRatesManagement.getRatesTable().getColumnModel().getColumn(0).setMinWidth(0);
			}
			
		}
	}

	@Override
	public void addController(Object obj) {
		pnlRatesApproval.addAncestorListener((AncestorListener)obj);
		pnlRatesApproval.getRatesTable().getDtm().addTableModelListener((TableModelListener)obj);
	}

}
